
#include "WiFiClient.h"
#include "WiFiUdp.h"

#include <Wire.h>
#include <time.h>

#include "NET_Ctrl.h"
#include "app_clock.h"
#include "oled.h"
#include "WiFi.h"
#include <Ticker.h>

#include "WiFiClientSecure.h"


Ticker TIM2;

tm *tt, ttm;


uint8_t tm_sec=0;
uint8_t tm_min=0;
uint8_t tm_hour=0;


void App_Clock_Init()
{
    tm* tt;
    tt = connectNTP();

    if (tt != NULL)
    {
        tm_hour = tt->tm_hour;
        tm_min  = tt->tm_min;
        tm_sec  = tt->tm_sec;

    }
    else
    {
        OLED_Debug("git time fail!!",3);
    }

    OLED_ClearPage(0,WHITE);
    OLED_ClearPage(1,0xaa);
    OLED_ClearPage(6,0xaa);
    OLED_ClearPage(7,WHITE);
    TIM2.attach(1,clock_run);
}





void clock_refresh()
{
    char msg[20];
    sprintf(msg,"%02d:%02d:%02d",tm_hour,tm_min,tm_sec);
    OLED_ShowString(0,16,msg,32);
}

void clock_run()
{
    tm_sec++;
    if(tm_sec>=60)
    {
        tm_sec=0;
        tm_min++;
        if (tm_min>=60)
        {
            /* code */
            tm_min=0;
            tm_hour++;
            if(tm_hour>=24)
            {
                tm_hour=0;
            }
        }
    }
}






